<template>
  <div class="approval">
    <el-card class="box-card" style="margin-top: 110px;">
      <div class="head-title2">
        <div class='title'>
          {{$t('achievements.title1')}}
        </div>
        <div class="info">
          <el-tooltip placement="left">
            <div slot="content">
              {{define}}
            </div>
            <div class="btns"></div>
          </el-tooltip>
        </div>
      </div>
      <div class="menu-search">
        <div class="menu-title">
          <!-- 入催日期 -->
          <div class="searchItem searchItem-date">
            <span>{{$t('inOutReminder.date')}}</span>
            <el-date-picker
              size="small"
              v-model="listQuery.collectDate"
              type="date"
              value-format="yyyy-MM-dd"
            ></el-date-picker>
          </div>
          <!-- 产品期限 -->
          <div class="searchItem">
            <span>{{$t('inOutReminder.productTerm')}}</span>
            <el-select v-model="listQuery.proTerm" size="small">
              <el-option
                v-for="(item, index) in productTerm"
                :key="index"
                :label="item.text"
                :value="item.value"
              ></el-option>
            </el-select>
          </div>
          <!-- 用户类型 -->
          <div class="searchItem">
            <span>{{$t('inOutReminder.userType')}}</span>
            <el-select v-model="listQuery.userType" size="small">
              <el-option
                v-for="item in userTypeArr"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              ></el-option>
            </el-select>
          </div>
          <!-- 用户等级 -->
          <div class="searchItem">
            <span>{{$t('inOutReminder.userLevel')}}</span>
            <el-select
              v-model="listQuery.userGrade"
              size="small"
            >
              <el-option
                v-for="item in gradeArr"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              ></el-option>
            </el-select>
          </div>
          <!-- 展期相关 -->
          <div class="searchItem searchItem-date">
            <span>{{$t('inOutReminder.extension')}}</span>
            <el-radio-group v-model="listQuery.collectType" size="small">
              <!-- 展期计入 -->
              <el-radio-button label="1" value="1">{{$t('inOutReminder.extension1')}}</el-radio-button>
              <!-- 展期不计入 -->
              <el-radio-button label="2" value="2">{{$t('inOutReminder.extension2')}}</el-radio-button>
            </el-radio-group>
          </div>
        </div>
        <div class="menu-title-btn">
          <button type="button" @click="search">{{$t('btn.query')}}</button>
          <button type="button" @click="reset">{{$t('btn.reset')}}</button>
          <button
            type="button"
            @click="handleDownload"
            :disabled="expDis"
            v-if="InOutReminder_btn_export"
          >{{$t('btn.export')}}</button>
        </div>
      </div>
    </el-card>
    
    <el-card class="box-card" style="margin-top: 10px;margin-bottom: 20px;">
      <div class="title">{{$t('DailyStatistics.ListDetails')}}</div>
      <el-table
        v-loading="listLoading"
        ref="multipleTable"
        :data="tableData"
        tooltip-effect="dark"
        style="width: 100%; margin-top: 5px;"
        @selection-change="handleSelectionChange"
        border
        size="mini"
      >
        <!-- 时间 -->
        <el-table-column
          header-align="center"
          align="center"
          width="120"
          prop="collectDate"
          :label="$t('inOutReminder.col1')"
        ></el-table-column>
        <!-- 订单入催量 -->
        <el-table-column
          header-align="center"
          align="center"
          prop="inCollectOrderAccount"
          width="120"
          :label="$t('inOutReminder.col2')"
        ></el-table-column>
        <!-- 入催金额 -->
        <el-table-column
          header-align="center"
          align="center"
          width="120"
          prop="inCollectAmtAccount"
          :formatter="cashFormatter"
          :label="$t('inOutReminder.col3')"
        ></el-table-column>
        <!-- 入催客户 -->
        <el-table-column
          header-align="center"
          align="center"
          width="120"
          prop="inCollectUserAccount"
          :label="$t('inOutReminder.col4')"
        ></el-table-column>
        <!-- 订单入催率 -->
        <el-table-column
          header-align="center"
          align="center"
          width="120"
          prop="inCollectOrderPercent"
          :label="$t('inOutReminder.col5')"
        ></el-table-column>
        <!-- 金额入催率 -->
        <el-table-column
          header-align="center"
          align="center"
          width="120"
          prop="inCollectAmtPercent"
          :label="$t('inOutReminder.col6')"
        ></el-table-column>
        <!-- 5天订单出催率 -->
        <el-table-column
          header-align="center"
          width="120"
          align="center"
          prop="outOrderPercent5"
          :label="$t('inOutReminder.col7')"
        ></el-table-column>
        <!-- 5天金额出催率 -->
        <el-table-column
          header-align="center"
          width="120"
          align="center"
          prop="outAmtPercent5"
          :label="$t('inOutReminder.col8')"
        ></el-table-column>
        <!-- 10天订单出催率 -->
        <el-table-column
          header-align="center"
          width="130"
          align="center"
          prop="outOrderPercent10"
          :label="$t('inOutReminder.col9')"
        ></el-table-column>
        <!-- 10天金额出催率 -->
        <el-table-column
          header-align="center"
          width="130"
          align="center"
          prop="outAmtPercent10"
          :label="$t('inOutReminder.col10')"
        ></el-table-column>
        <!-- 20天订单出催率 -->
        <el-table-column
          header-align="center"
          width="130"
          align="center"
          prop="outOrderPercent20"
          :label="$t('inOutReminder.col11')"
        ></el-table-column>
        <!-- 20天金额出催率 -->
        <el-table-column
          header-align="center"
          align="center"
          width="130"
          prop="outAmtPercent20"
          :label="$t('inOutReminder.col12')"
        ></el-table-column>
      </el-table>
      <!-- <div class="pagination-container">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="listQuery.page"
          :page-sizes="[5, 10, 20, 30]"
          :page-size="listQuery.limit"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        ></el-pagination>
      </div> -->
    </el-card>
  </div>
</template>

<script>
import { mapGetters } from 'vuex';
import { formatCash } from 'utils/index'
import { getProdDeadline } from 'api/reportStatistics/LoanReport/index';
import { mbReport, mbReportExport } from 'api/reportForm/InOutReminder/index';
export default {
  data() {
    return {
      define: '',
      // changeDate: [new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate() - 7), new Date()],
      InOutReminder_btn_export: false,
      listLoading: false,
      total: null,
      expDis: true,
      listQuery: {
        // limit: 5,
        // page: 1,
        // 入催时间
        collectDate: '',
        // 产品期限（与资金回收报表入参一致）
        proTerm: '0',
        // 用户类型	0.全部1.老用户2.新用户
        userType: '0',
        // 用户等级（先不考虑这个）
        userGrade: '',
        // 1.展期计入 2.展期不计入
        collectType: '1'
      },
      tableData: [],
      multipleSelection: [],
      productTerm: [{ text: this.$t('rule.all'), value: '0' }],
      userTypeArr: [
        {
          id: '0',
          name: this.$t('rule.all')
        },
        {
          id: '1',
          name: this.$t('LoanReport.newUser')
        },
        {
          id: '2',
          name: this.$t('LoanReport.oldUser')
        }
      ],
      gradeArr: [
        {
          id: '',
          name: this.$t('rule.all')
        }
      ],
      info: {}
    };
  },
  computed: {
    ...mapGetters(['elements', 'inOutReminderPage', 'getReportDefine'])
  },
  created() {
    if (this.inOutReminderPage.has(this.$route.path)) {
      this.listQuery = this.inOutReminderPage.get(this.$route.path);
    }
    this.getTime();
    this.getList();
    // 产品期限
    getProdDeadline().then(res => {
      if (res.data !== '') {
        const data = res.data.map(val => {
          const text = val + this.$t('processing.day')
          return {
            text,
            value: val
          }
        });
        this.productTerm = this.productTerm.concat(data)
      }
    });
    this.InOutReminder_btn_export = this.elements['inOutReminder:btn_export'];
    // 获取报表定义
    this.getReportDefine.forEach(item => {
      if (item.dictCode === 'IMPORT_REMINDER_REPORT') {
        this.define = item.dictValue
      }
    })
  },
  methods: {
    cashFormatter(row, col, cellValue) {
      return formatCash(cellValue)
    },
    // 点击导出
    handleDownload() {
      this.listLoading = true;
      mbReportExport(this.listQuery).then(res => {
        require.ensure([], () => {
          const { export_json_to_excel } = require('@/vendor/Export2Excel');
          const tHeader = [
            this.$t('inOutReminder.col1'),
            this.$t('inOutReminder.col2'),
            this.$t('inOutReminder.col3'),
            this.$t('inOutReminder.col4'),
            this.$t('inOutReminder.col5'),
            this.$t('inOutReminder.col6'),
            this.$t('inOutReminder.col7'),
            this.$t('inOutReminder.col8'),
            this.$t('inOutReminder.col9'),
            this.$t('inOutReminder.col10'),
            this.$t('inOutReminder.col11'),
            this.$t('inOutReminder.col12')
          ];
          const filterVal = [
            'collectDate',
            'inCollectOrderAccount',
            'inCollectAmtAccount',
            'inCollectUserAccount',
            'inCollectOrderPercent',
            'inCollectAmtPercent',
            'outOrderPercent5',
            'outAmtPercent5',
            'outOrderPercent10',
            'outAmtPercent10',
            'outOrderPercent20',
            'outAmtPercent20'
          ];
          const data = res.data;
          if (data) {
            const list = [data];
            const list2 = this.formatJson(filterVal, list);
            export_json_to_excel(tHeader, list2, this.$t('route.inOutReminder'));
          }
          this.listLoading = false;
        });
      });
    },
    formatJson(filterVal, jsonData) {
      return jsonData.map(v => filterVal.map(j => v[j]));
    },
    getList() {
      this.listLoading = true;
      this.$store.dispatch('saveInOutReminderPage', {
        path: this.$route.path,
        listQuery: this.listQuery
      });
      mbReport(this.listQuery).then(res => {
        if (res && res.status === 200) {
          const data = res.data
          if (data) {
            const list = [data]
            this.expDis = false;
            this.listLoading = false;
            this.tableData = list
          }
        }
        // const re = /(?=(?!\b)(\d{3})+$)/g;
        // res.data.listBackVo.forEach(item => {
        //   let str = String(item.loanTotalAmt);
        //   item.loanTotalAmt = str.replace(re, ",");
        //   let str2 = String(item.backTotalAmt);
        //   item.backTotalAmt = str2.replace(re, ",");
        // });
        // this.expDis = false;
        // this.listLoading = false;
        // this.tableData = res.data.listBackVo;
        // let str3 = String(res.data.totalMap.totallentAmt);
        // res.data.totalMap.totallentAmt = str3.replace(re, ",");
        // let str4 = String(res.data.totalMap.totalBackAmt);
        // res.data.totalMap.totalBackAmt = str4.replace(re, ",");
        // this.info = res.data.totalMap;
        // this.total = Number(res.data.total);
      });
    },
    getTime() {
      this.listQuery.collectDate = this.GetDateStr(-20);
    },
    GetDateStr(AddDayCount) {
      const dd = new Date();
      dd.setDate(dd.getDate() + AddDayCount);// 获取AddDayCount天后的日期
      const y = dd.getFullYear();
      const m = (dd.getMonth() + 1) < 10 ? '0' + (dd.getMonth() + 1) : (dd.getMonth() + 1); // 获取当前月份的日期，不足10补0
      const d = dd.getDate() < 10 ? '0' + dd.getDate() : dd.getDate(); // 获取当前几号，不足10补0
      return y + '-' + m + '-' + d;
    },
    // 查询
    search() {
      this.listQuery.page = 1;
      this.getList();
    },
    // 重置
    reset() {
      this.listQuery.proTerm = '0';
      this.listQuery.userType = '0';
      this.listQuery.userGrade = '';
      this.listQuery.collectType = '1';
      this.getTime();
      // this.changeDate = [new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate() - 7), new Date()];
    },
    // 选中的数据
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    handleSizeChange(val) {
      this.listQuery.limit = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.listQuery.page = val;
      this.getList();
    }
  }
};
</script>

<style scoped lang='scss'>
.box-card {
  width: 95%;
  margin-left: 2.5%;
  margin-right: 2.5%;
}
.title {
  line-height: 30px;
  font-size: 16px;
  display: flex;
  align-items: center;
  font-weight: bold;
}
.title:before {
  display: block;
  content: "";
  width: 3px;
  height: 16px;
  background-color: #309afe;
}
.title:before {
  margin-right: 8px;
}
::before {
  box-sizing: inherit;
  -webkit-tap-highlight-color: transparent;
}
.menu-title {
  width: 100%;
  box-sizing: border-box;
  background: #ffffff;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  .searchItem {
    display: flex;
    align-items: center;
    padding: 10px 0;
    span {
      display: inline-block;
      width: 100px;
      text-align: right;
      font-size: 12px;
      color: #5f5f61;
      padding-right: 5px;
    }
    div:nth-child(2) {
      width: 150px;
    }
  }
  .searchItem-date {
    display: flex;
    align-items: center;
    padding: 10px 0;
    span {
      display: inline-block;
      width: 100px;
      text-align: right;
      font-size: 12px;
      color: #5f5f61;
      padding-right: 5px;
    }
    div:nth-child(2) {
      width: 220px;
    }
  }
}
.menu-title-btn {
  padding: 10px 0;
  box-sizing: border-box;
  button {
    padding: 0 20px;
    height: 28px;
    background: #20a0ff;
    color: #fff;
    outline: none;
    border-width: 0;
    border-radius: 4px;
    font-size: 12px;
    margin-left: 10px;
    &:nth-child(1) {
      margin-left: 0;
    }
    &:nth-child(2) {
      background: #ebf5ff;
      color: #20a0ff;
      border: 1px solid #abd5ff;
    }
  }
  button[disabled] {
    padding: 0 20px;
    height: 28px;
    background: #c1e0ff;
    color: #fafbff;
    outline: none;
    border-width: 0;
    border-radius: 4px;
    font-size: 12px;
  }
}
.menu-list {
  padding: 20px 0;
  box-sizing: border-box;
  button {
    padding: 0 20px;
    height: 28px;
    background: #20a0ff;
    color: #fff;
    outline: none;
    border-width: 0;
    border-radius: 4px;
    font-size: 12px;
    margin-left: 10px;
    &:nth-child(1) {
      margin-left: 0;
    }
  }
  button[disabled] {
    padding: 0 20px;
    height: 28px;
    background: #c1e0ff;
    color: #fafbff;
    outline: none;
    border-width: 0;
    border-radius: 4px;
    font-size: 12px;
  }
}
.info-overview {
  display: flex;
  justify-content: space-around;
  text-align: center;
  .info-item {
    flex: 1;
    .info-circle {
      width: 130px;
      height: 130px;
      line-height: 130px;
      text-align: center;
      border-radius: 50%;
      border: 2px solid rgb(129, 125, 125);
      margin-top: 5px;
      margin-bottom: 8px;
      margin-left: auto;
      margin-right: auto;
      font-size: 18px;
      font-weight: bold;
    }
    .info-text {
      font-size: 14px;
      line-height: 20px;
    }
  }
}
.head-title2 {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.btns {
  display: inline-block;
  width: 24px;
  height: 24px;
  background-size: cover;
  background-image: url("../../../assets/images/question-mark.svg");
}
</style>